﻿// $Id$
/*! \file
 * \brief Definition of Northwind.DomainModel.EnterpriseLibrary.EmployeeMapper.
 *
 * \author $Author$
 * \date $Date$
 * \version $Revision$
 */

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Salamanca.DataAccess;
using Salamanca.DataAccess.Collections;
using Salamanca.DataAccess.EnterpriseLibrary.Data;

namespace Northwind.DomainModel.EnterpriseLibrary
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ///////////////////////////////////////////////////////////////////////////

    public partial class EmployeeMapper:
        DataMapper<Employee, Employee.PrimaryKey, Employee.DataTransfer>,
        IEmployeeMapper
    {

        /// <summary />
        public EmployeeMapper(Database database, ICacheManager cacheManager):
            base(database, DomainModelCreator.CreateDefault<Employee>(), cacheManager)
        {
            _ParameterBuilder=new Salamanca.DataAccess.Data.ParameterBuilder(database.CreateConnection());
        }

        /// <summary />
        public DomainModelKeyedCollection<Employee> FindAll(DataMapperCollection dataMappers)
        {
            return _FindAll(dataMappers);
        }

        /// <summary />
        protected override IList<DbCommand> CreateSelectCommands(Employee.PrimaryKey key)
        {
            return CreateSelectCommands(Database, ParameterBuilder, key);
        }

        /// <summary />
        protected override IList<DbCommand> CreateDeleteCommands(Employee.DataTransfer data)
        {
            return CreateDeleteCommands(Database, ParameterBuilder, (Employee.DataTransfer)data);
        }

        /// <summary />
        protected override IList<DbCommand> CreateInsertCommands(Employee.DataTransfer data)
        {
            return CreateInsertCommands(Database, ParameterBuilder, (Employee.DataTransfer)data);
        }

        /// <summary />
        protected override IList<DbCommand> CreateUpdateCommands(Employee.DataTransfer data)
        {
            return CreateUpdateCommands(Database, ParameterBuilder, (Employee.DataTransfer)data);
        }

        /// <summary />
        protected override Employee.DataTransfer GetDataTransferObject(IList<IDataRecord> records)
        {
          return _GetDataTransferObject(records);
        }

        /// <summary />
        protected override void OnInserted(Employee domainModel, IList<DbCommand> commands)
        {
            domainModel.SetId(Utils.GetLastId(Database, commands));

            base.OnInserted(domainModel, commands);
        }

        /// <summary />
        internal static IList<DbCommand> CreateSelectCommands(Database database, Salamanca.DataAccess.Data.ParameterBuilder parameterBuilder, Employee.PrimaryKey key)
        {
            return new DbCommand[] { _CreateSelectCommand(database, parameterBuilder, key) };
        }

        /// <summary />
        internal static IList<DbCommand> CreateDeleteCommands(Database database, Salamanca.DataAccess.Data.ParameterBuilder parameterBuilder, Employee.DataTransfer data)
        {
            return new DbCommand[] { _CreateDeleteCommand(database, parameterBuilder, (Employee.DataTransfer)data) };
        }

        /// <summary />
        internal static IList<DbCommand> CreateInsertCommands(Database database, Salamanca.DataAccess.Data.ParameterBuilder parameterBuilder, Employee.DataTransfer data)
        {
            return new DbCommand[] { _CreateInsertCommand(database, parameterBuilder, (Employee.DataTransfer)data) };
        }

        /// <summary />
        internal static IList<DbCommand> CreateUpdateCommands(Database database, Salamanca.DataAccess.Data.ParameterBuilder parameterBuilder, Employee.DataTransfer data)
        {
            return new DbCommand[] { _CreateUpdateCommand(database, parameterBuilder, (Employee.DataTransfer)data) };
        }

    }
}
